package org.hoyi.util;

import javax.servlet.http.HttpServletRequest;


/**
 *          Author:ellen
 *          Email:ellen@kuaifish.com
 *          CreateDate:2015-05-20
 *          ModifyDate:2015-06-20
 *          hoyi entities @ hoyi.org
 *          使用请在项目关于内标注hoyi版权，
 *          hoyi版权归hoyi.org所有
 */
public class PGUTIL {
	private static PGUTIL _instance;

	public static PGUTIL I() {
		if (_instance == null) {
			_instance = new PGUTIL();
		}
		return _instance;
	}

	public String CATPGS(HttpServletRequest request, int i) {
		String filters = request.getParameter("FILTER");
		String pgcStr = "";
		if (filters != null)
			pgcStr = " onclick=\"pgc(" + i + ", 'LOCATION')\"";
		else {
			pgcStr = " onclick=\"pgc(" + i + ", 'ALL')\"";
		}
		return pgcStr;
	}

	public String CATPGS(HttpServletRequest request, int i, String methodname) {
		String filters = request.getParameter("FILTER");
		String pgcStr = "";
		if (filters != null)
			pgcStr = " onclick=\"" + methodname + "(" + i + ", 'LOCATION')\"";
		else {
			pgcStr = " onclick=\"" + methodname + "(" + i + ", 'ALL')\"";
		}
		return pgcStr;
	}

	public String CATPGS(HttpServletRequest request, int i, String methodname,
			String params) {
		String filters = request.getParameter("FILTER");
		String pgcStr = "";
		if (filters != null)
			pgcStr = " onclick=\"" + methodname + "(" + i + "," + params
					+ ")\"";
		else {
			pgcStr = " onclick=\"" + methodname + "(" + i + "," + params
					+ ")\"";
		}
		return pgcStr;
	}

	public String GETNAVIHTML(HttpServletRequest request, int pagecount,
			int pgindex) {
		String result = "<li><a " + I().CATPGS(request, 0)
				+ " href=\"#\">&laquo;</a></li>   ";

		for (int i = 0; i < pagecount; i++) {
			if (i == pgindex)
				result = result
						+ "<li><a style=\"background-color:#dddddd; color:white;\" "
						+ I().CATPGS(request, i) + " href=\"#\">" + (i + 1)
						+ "</a></li>";
			else {
				result = result + "<li><a " + I().CATPGS(request, i)
						+ " href=\"#\">" + (i + 1) + "</a></li>";
			}
		}
		int ccc = pagecount - 1;
		result = result + "<li><a " + I().CATPGS(request, ccc) + " href=\"#\">&raquo;</a></li>";
		return result;
	}

	public String GETNAVIHTML(HttpServletRequest request, int pagecount,
			int pgindex, String methodname) {
		String result = "<li><a " + I().CATPGS(request, 0, methodname)
				+ " href=\"#\">&laquo;</a></li>   ";

		for (int i = 0; i < pagecount; i++) {
			if (i == pgindex)
				result = result
						+ "<li><a style=\"background-color:#dddddd; color:white;\" "
						+ I().CATPGS(request, i, methodname) + " href=\"#\">"
						+ (i + 1) + "</a></li>";
			else {
				result = result + "<li><a "
						+ I().CATPGS(request, i, methodname) + " href=\"#\">"
						+ (i + 1) + "</a></li>";
			}
		}
		int ccc = pagecount - 1;
		result = result + "<li><a " + I().CATPGS(request, ccc, methodname)
				+ " href=\"#\">&raquo;</a></li>";
		return result;
	}

	public String GETNAVIHTML(HttpServletRequest request, int pagecount,
			int pgindex, String methodname, String params) {
		String result = "<li><a " + I().CATPGS(request, 0, methodname, params)
				+ " href=\"#\">&laquo;</a></li>   ";

		for (int i = 0; i < pagecount; i++) {
			if (i == pgindex)
				result = result
						+ "<li><a style=\"background-color:#dddddd; color:white;\" "
						+ I().CATPGS(request, i, methodname, params)
						+ " href=\"#\">" + (i + 1) + "</a></li>";
			else {
				result = result + "<li><a "
						+ I().CATPGS(request, i, methodname, params)
						+ " href=\"#\">" + (i + 1) + "</a></li>";
			}
		}
		int ccc = pagecount - 1;
		result = result + "<li><a "
				+ I().CATPGS(request, ccc, methodname, params)
				+ " href=\"#\">&raquo;</a></li>";
		return result;
	}
}